<template>
	<div>
		<!-- 顶部选项卡 -->
		<scroll-view class="pagecontrol-top-scroll" scroll-x="true" scroll-with-animation
			:scroll-into-view="scrollInto">
			<view class="pagecontrol-top-title">
				<view v-for="(items, index) in itemsArr" :key="index" class="pagecontrol-top-text"
					@click="changeTab(index)" :id="'tab' + index">
					<view :class="tabIndex === index ? 'pagecontrol-top-selected' : 'pagecontrol-top-normal'">
						{{ items }}
					</view>
					<view class="pagecontrol-bottom-line"
						:class="tabIndex === index ? 'pagecontrol-bottom-line-show' : 'pagecontrol-bottom-line-visibility'">
					</view>
				</view>
			</view>
		</scroll-view>
		<!-- 内容 -->
		<swiper :duration="150" :current="tabIndex" @change="onChangeTab" :style="'height:' + scrollH + 'px;'">
			<swiper-item>
				<scroll-view scroll-y="true" show :style="'height:' + scrollH + 'px;'">
					<!--订单信息-->
					<view style="padding-bottom: 100px;">
						<view v-if="formData.orderCode" style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;font-weight: bold;">
							平台订单号：{{formData.orderCode}}
						</view>
						<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px 15px 25px;display: flex;flex-direction: row;">
							<view style="width: 50px;display: flex;flex-direction: column;">
								<view style="height: 24px;width: 24px;border-radius: 50%;background-color: #464646;color: #ffffff;display: flex;justify-content: center;align-items: center;">发</view>
							    <view style="height: 112px;width: 1px;border-left: 1rpx dashed #bf6006;margin-left: 11px;"></view>
								<view style="height: 24px;width: 24px;border-radius: 50%;background-color: #bf6006;color: #ffffff;display: flex;justify-content: center;align-items: center;">收</view>
							</view>
							<view style="display: flex;flex-direction: column;width: 100%;">
								<view style="display: flex;width: 100%;">
									<!--发货方-->
									<view style="display: flex;flex-direction: column;width: 100%;">
									    <text style="font-size: 16px;font-weight: bold;">发货方信息</text>
									    <span style="display: flex;justify-content: space-between;margin-top: 10px;">
											<uni-data-select :disabled="formData.parentId!=0" @change="selectShipId" v-model="formData.shipId" :localdata="shipId" placeholder="请选择发货方"
												style="background-color: white;width: 100%;" />
									    </span>
									    <span v-if="formData.originDistractId==''||formData.originDistractId==null" style="display: flex;margin-bottom: 13px;height: 37px;align-items: center;">
									    	<input disabled placeholder="请从地址簿选择发货地址" style="border: none;width: 80%;"/>
									    </span>
										<span v-else style="display: flex;flex-direction: column;margin-top: 10px;">
											<span>
												<text style="font-size: 16px;font-weight: bold;">{{formData.shipContacts}}</text>
												<text style="margin-left: 10px;">{{formData.shipContactTel}}</text>
											</span>
											<span style="color: #6f6f6f;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">
												{{formData.originDistractName}}{{formData.originAddress}}
											</span>
										</span>
								    </view>
									<view style="display: flex;align-items: center;width: 60px;margin-top: 62px;">
										<span style="display: flex;align-items: center;font-size: 14px;">
											<view style="width: 1px;height: 14px;background-color: #e7e7e7;margin-right: 5px;"></view>
											<view @click="open_shipAddress" hover-class="buttonHover" style="font-weight: bold;">地址薄</view>
										</span>
									</view>
								</view>
								<!--分割线-->
								<view style="height: 1px;width: 100%;display: flex;justify-content: center;margin: 10px 0;"></view>
								<view style="display: flex;width: 100%;">
									<!--收货方-->
									<view style="display: flex;flex-direction: column;width: 100%;">
									    <text style="font-size: 16px;font-weight: bold;">收货方信息</text>
									    <span style="display: flex;justify-content: space-between;margin-top: 10px;">
									    	<uni-data-select :disabled="formData.parentId!=0" @change="selectDeliveryId" v-model="formData.deliveryId" :localdata="deliveryId" placeholder="请选择收货方"
									    		style="background-color: white;width: 100%;" />
									    </span>
									    <span v-if="formData.destinationDistractId==''||formData.destinationDistractId==null" style="display: flex;margin-bottom: 13px;height: 37px;align-items: center;">
											<input disabled placeholder="请从地址簿选择收货地址" style="border: none;width: 80%;"/>
									    </span>
										<span v-else style="display: flex;flex-direction: column;margin-top: 10px;">
											<span>
												<text style="font-size: 16px;font-weight: bold;">{{formData.deliveryContacts}}</text>
												<text style="margin-left: 10px;">{{formData.deliveryContactTel}}</text>
											</span>
											<span style="color: #6f6f6f;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">
												{{formData.destinationDistractName}}{{formData.destinationAddress}}
											</span>
										</span>
								    </view>
									<view style="display: flex;align-items: center;width: 60px;margin-top: 62px">
										<span style="display: flex;align-items: center;font-size: 14px;">
											<view style="width: 1px;height: 14px;background-color: #e7e7e7;margin-right: 5px;"></view>
											<view @click="open_deliveryAddress" hover-class="buttonHover" style="font-weight: bold;">地址薄</view>
										</span>
									</view>
								</view>
							</view>
						</view>
						<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
							<uni-forms ref="form" :modelValue="formData" :rules="rules" labelWidth="100px">
								<!-- <uni-forms-item label="所属项目" name="projectId" required>
									<uni-data-select @change="selectProjectId" v-model="formData.projectId" :localdata="projectId"
										style="background-color: white;" />
								</uni-forms-item> -->
								<!-- <uni-forms-item label="发货方" name="shipId" required>
									<uni-data-select @change="selectShipId" v-model="formData.shipId" :localdata="shipId"
										style="background-color: white;" />
								</uni-forms-item>
								<uni-forms-item label="收货方" name="deliveryId" required>
									<uni-data-select @change="selectDeliveryId" v-model="formData.deliveryId" :localdata="deliveryId"
										style="background-color: white;" />
								</uni-forms-item>
								<uni-forms-item label="始发地" name="originDistractId" required>
									<uni-data-picker placeholder="请选择地址" popup-title="请选择所在地区" :localdata="originDistractId"
										style="background-color: white;" v-model="formData.originDistractId">
									</uni-data-picker>
									<view style="margin-top: 20px;">
										<uni-easyinput  type="text"
											v-model="formData.originAddress" placeholder="请输入详细地址" />
									</view>
								</uni-forms-item>
								<uni-forms-item label="目的地" name="destinationDistractId" required>
									<uni-data-picker placeholder="请选择地址" popup-title="请选择所在地区" :localdata="originDistractId"
										style="background-color: white;" v-model="formData.destinationDistractId">
									</uni-data-picker>
									<view style="margin-top: 20px;">
										<uni-easyinput  type="text"
											v-model="formData.destinationAddress" placeholder="请输入详细地址" />
									</view>
								</uni-forms-item> -->
								
								<uni-forms-item label="货主订单号" name="ownerOutCode" required>
									<uni-easyinput :disabled="formData.parentId!=0" type="text" v-model="formData.ownerOutCode" placeholder="请输入货主订单号" />
								</uni-forms-item>
								<uni-forms-item label="提货单号" name="pickupOrderNo" required>
									<uni-easyinput :disabled="formData.parentId!=0" type="text" v-model="formData.pickupOrderNo" placeholder="请输入提货单号" />
								</uni-forms-item>
								<uni-forms-item label="计划提货时间" name="pickupTime" required>
									<uni-datetime-picker hide-second type="datetime" v-model="formData.pickupTime" @change="selectPickupTime"/>
								</uni-forms-item>
								<uni-forms-item label="计划到达时间" name="arrivalTime" required>
									<uni-datetime-picker hide-second type="datetime" v-model="formData.arrivalTime" @change="selectArrivalTime"/>
								</uni-forms-item>
								<!-- <uni-forms-item label="预约提货时间" name="pickupTime">
									<uni-datetime-picker type="date" v-model="formData.pickupTime" />
								</uni-forms-item>
								<uni-forms-item label="预约送货时间" name="deliveryTime">
									<uni-datetime-picker type="date" v-model="formData.deliveryTime" />
								</uni-forms-item> -->
								<uni-forms-item label="备注" name="remark">
									<uni-easyinput type="textarea" v-model="formData.remark" placeholder="订单相关备注说明" />
								</uni-forms-item>
							</uni-forms>
							
						</view>
					</view>
				</scroll-view>
				<view
					style="background-color: #ffffff;z-index: 3;height: 70px;width:100%;position: fixed;bottom: 0;display: flex;box-shadow: 0px 0px 11px rgba(0, 0, 0, 0.1);">
					<view
						style="display: flex;align-items: center;width: 100%;height: 60px;justify-content: center;">
						<view v-if="goodOrderId==''" @click="submit()" hover-class="buttonHover"
							style="height: 35px;background-color: #bf5f09;color: #ffffff;width: 100px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">
							确定新增</view>
						<view v-else @click="submit_update()" hover-class="buttonHover"
							style="height: 35px;background-color: #bf5f09;color: #ffffff;width: 100px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">
							保存</view>
					</view>
				</view>
			</swiper-item>
			<swiper-item>
				<scroll-view scroll-y="true" show :style="'height:' + scrollH + 'px;'">
					<!--货物信息-->
					<view  style="padding-bottom: 100px;">
						<view class="source" v-for="(item,index) in goodSourceList" :key="index">
							<view style="display: flex;align-items: center;width: 100%;">
								<view style="margin-left: 10px;margin-right: 10px;width: 100%;">
									<view style="display: flex;justify-content: space-between;">
										<text>{{item.goodCode}}</text>
										<text>{{item.goodsName}}</text>
										<text>{{goodsType[item.goodsType]}}</text>
										<text>{{packingType[itme.packingType]}}</text>
										<text>{{item.produceCompany}}</text>
									</view>
									<view style="color: #a5a5a5;font-size: 14px;">
										<text>{{item.goodsDesc}}</text>
									</view>
									<view style="display: flex;flex-direction: row;align-items: center;">
											<input type="number" :disabled="formData.parentId!=0" v-model="item.num" style="height:35px;flex: 1;border: 1px solid #F0F0F0;border-color: rgb(229, 229, 229);border-radius: 4px;background-color: white;padding-left: 10px;"/>
											<view style="flex: 1;margin-left: 5px;">/件</view>
											<input type="number" :disabled="formData.parentId!=0" v-model="item.weight" style="height:35px;flex: 1;margin-left: 5px;border: 1px solid #F0F0F0;border-color: rgb(229, 229, 229);border-radius: 4px;background-color: white;padding-left: 10px;"/>
											<view style="flex: 1;margin-left: 5px;">/吨</view>
											<input type="number" :disabled="formData.parentId!=0" v-model="item.bulk" style="height:35px;flex: 1;margin-left: 5px;border: 1px solid #F0F0F0;border-color: rgb(229, 229, 229);border-radius: 4px;background-color: white;padding-left: 10px;"/>
											<view style="flex: 1;margin-left: 5px;">/立方米</view>
									</view>
									<view style="color: #a5a5a5;font-size: 14px;display: flex;justify-content: space-between;">
										<span>
											<text>上市时间：</text>
											<text style="margin-left: 5px;">{{item.marketTime}}</text>
										</span>
									</view>
									<!-- <view>
										产品手册{{item.productManual}} 质检报告{{item.qualityReport}} 其他材料{{item.otherFiles}}
									</view> -->
								</view>
							</view>
							<view style="display: flex;position: absolute;right: 10px;bottom: 10px;">
								<view @click="deleteGoodSourceList(index)" hover-class="buttonHover" style="margin-left: 10px;width: 60px;text-align: center;background-color:#bf5f09;color:#ffffff;border-radius: 8px;font-size: 14px;">移除</view>
							</view>
							
						</view>
						<!-- <view  @click="addGoodSourceList" hover-class="buttonHover" style="position: fixed;left: 50%;transform:translateX(-50%);bottom:10px;width: 100px;height:35px;color:#ffffff;background-color:#bf5f09;border-radius: 4px;display:flex;justify-content: center;align-items: center;">
							新增货物
						</view> -->
						<view @click="addGoodSourceList" hover-class="buttonHover" style="position: fixed;right: 15px;bottom:100px;width: 50px;height:50px;color:#ffffff;background-color:#bf5f09;border-radius: 50%;display:flex;justify-content: center;align-items: center;box-shadow: 0 1px 5px 2px rgba(0, 0, 0, 0.3);">
							<uni-icons type="plusempty" size="30" color="#ffffff"></uni-icons>
						</view>
					</view>
				</scroll-view>
				<view
					style="background-color: #ffffff;z-index: 3;height: 70px;width:100%;position: fixed;bottom: 0;display: flex;box-shadow: 0px 0px 11px rgba(0, 0, 0, 0.1);">
					<view
						style="display: flex;align-items: center;width: 100%;height: 60px;justify-content: center;">
						<view v-if="goodOrderId==''" @click="submit()" hover-class="buttonHover"
							style="height: 35px;background-color: #bf5f09;color: #ffffff;width: 100px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">
							确定新增</view>
						<view v-else @click="submit_update()" hover-class="buttonHover"
							style="height: 35px;background-color: #bf5f09;color: #ffffff;width: 100px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">
							保存</view>
					</view>
				</view>
			</swiper-item>
		</swiper>
		<!-- 发货地址簿弹窗 -->
		<uni-popup ref="alertDialog_address_ship" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定" title="地址薄" @confirm="dialogConfirm_address_ship">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<radio-group @change="radioChange_ship">
							<label v-for="(item, index) in addressList_ship" :key="index"
								style="display: flex;flex-direction: column;background-color: white;padding: 15px;border-bottom: 1rpx solid #ededed;">
								<view style="display: flex;">
									<text>{{item.contactName}}</text>
									<text style="margin-left: 20px;">{{item.phone}}</text>
								</view>
								<view style="position: relative;margin-top: 10px;">
									<radio :value="JSON.stringify(item)" :checked="item.id===address_ship.id"/>
									<text style="margin-left: 10px;">{{item.bookDistrictName}}{{item.bookAddress}}</text>
								</view>
							</label>
						</radio-group>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 收货地址簿弹窗 -->
		<uni-popup ref="alertDialog_address_delivery" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定" title="地址薄" @confirm="dialogConfirm_address_delivery">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<radio-group @change="radioChange_delivery">
							<label v-for="(item, index) in addressList_delivery" :key="index"
								style="display: flex;flex-direction: column;background-color: white;padding: 15px;border-bottom: 1rpx solid #ededed;">
								<view style="display: flex;">
									<text>{{item.contactName}}</text>
									<text style="margin-left: 20px;">{{item.phone}}</text>
								</view>
								<view style="position: relative;margin-top: 10px;">
									<radio :value="JSON.stringify(item)" :checked="item.id===address_delivery.id"/>
									<text style="margin-left: 10px;">{{item.bookDistrictName}}{{item.bookAddress}}</text>
								</view>
							</label>
						</radio-group>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 新增货物弹窗 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定" title="新增货物" @confirm="dialogConfirm">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<uni-data-checkbox  multiple v-model="goods" :localdata="allGoodsList"></uni-data-checkbox>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
	</div>
</template>

<script>
	import {getCustomerList} from '@/api/system/customer.js'
	import {getProjectList} from '@/api/system/project.js'
	import {getSourceList} from '@/api/system/source.js'
	import {
		getOrderDetails,
		addOrder,
		updateOrderProfile
	} from '@/api/system/order.js'
	import {getDicts,getAllAddressTree} from '@/api/system/dict.js'
	
	export default {
		data() {
			return {
				itemsArr: ['订单信息', '货物信息'],
				tabIndex: 0,
				scrollH: 700,
				scrollInto: '',
				formData: {
					shipId: '',
					deliveryId:'',
					projectId:'',
					ownerOutCode: '',
					shipContacts:'',
					shipContactTel:'',
					originDistractId: '',
					originAddress: '',
					deliveryContacts:'',
					deliveryContactTel:'',
					destinationDistractId: '',
					destinationAddress:'',
					pickupTime:'',
					arrivalTime:'',
					pickupTime:'',
					deliveryTime:'',
					remark: '',
					parentId:'0'  //0代表母订单
				},
				// 校验规则
				rules: {
					// projectId:{
					// 	rules: [{
					// 		required: true,
					// 		errorMessage: '请选择项目',
					// 	}]
					// },
					shipId: {
						rules: [{
							required: true,
							errorMessage: '请选择发货方',
						}]
					},
					deliveryId: {
						rules: [{
							required: true,
							errorMessage: '请选择收货方',
						}]
					},
					ownerOutCode: {
						rules: [{
							required: true,
							errorMessage: '请输入货主订单号',
						}]
					},
					pickupOrderNo: {
						rules: [{
							required: true,
							errorMessage: '请输入提货单号',
						}]
					},
					originDistractId: {
						rules: [{
							required: true,
							errorMessage: '请选择始发地址',
						}]
					},
					destinationDistractId: {
						rules: [{
							required: true,
							errorMessage: '请选择目的地址',
						}]
					},
					pickupTime: {
						rules: [{
							required: true,
							errorMessage: '请选择计划提货时间',
						}]
					},
					arrivalTime: {
						rules: [{
							required: true,
							errorMessage: '请选择计划到达时间',
						}]
					},
				},
				
				//回显顾客列表
				customerList:[],
				
				//下拉框 ->发货方
				shipId: [],
				//下拉框 ->收货方
				deliveryId: [],
				//下拉框 ->所属项目
				projectId: [],
				//项目列表
				projectList:[],
				//地区下拉框
				originDistractId: [],
				
				imageStyles: {
					width: 250,
					height: 200,
					border: {
						radius: '4px'
					}
					
				},
				//回显的货物列表
				goodSourceList:[],
				//货物类型
				goodsType:[],
				//包装类型
				packingType:[],
				
				//用来模拟的，以后要删除
				howPiece:'',
				howTon:'',
				howStere:'',
				
				goodOrderId:'',
				
				//货物信息的货物列表
				allGoodsList:[],
				goods:[],
				
				//回显的地址列表
				addressList_ship:[],
				addressList_delivery:[],
				
				//地址弹窗选择的地址
				address_ship:{},
				address_delivery:{},
			}
		},
		onLoad(e) {
			uni.getSystemInfo({
				success: res => {
					this.scrollH = res.windowHeight - 40;
				}
			});
			
			if (e.goodOrderId) {
				//设置顶部导航栏标题
				uni.setNavigationBarTitle({
					title: '编辑订单'
				})
			
				uni.showLoading({
					title: '正在加载',
				})
				this.goodOrderId = e.goodOrderId
				//获取订单详情
				getOrderDetails(e.goodOrderId).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						this.formData = res.data
						this.goodSourceList=this.formData.goodSourceList||[]
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
			
				})
			}
		},
		created() {
			//获取客户列表
			getCustomerList({pageNum:1,pageSize:1000}).then(res => {
				if (res.code == '200') {
					//发货方下拉数据
					this.shipId = res.rows.map(item => {
						return {
							value: item.customerId,
							customer:JSON.stringify(item),
							text: item.customerName
						}
					})
					//收货方下拉数据
					this.deliveryId = JSON.parse(JSON.stringify(this.shipId))
				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
			})
			//获取项目列表
			getProjectList({pageNum:1,pageSize:1000}).then(res => {
				if (res.code == '200') {
					this.projectList=res.rows
					this.projectId=res.rows.map(item=>{
						return {
							value:item.id,
							text:item.projectName+' '+item.leader+' '+item.phone,
						}
					})
				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
			})
			
			//加载货物类型
			getDicts('goods_type').then(res=>{
				res.data.forEach(item=>{
					this.goodsType[item.dictValue]=item.dictLabel
				})
			})
			//加载包装类型
			getDicts('packing_type').then(res=>{
				res.data.forEach(item=>{
					this.packingType[item.dictValue]=item.dictLabel
				})
			})
			
			//获取全国地址信息->地区下拉框
			getAllAddressTree().then(res=>{
				this.originDistractId=res.data
			})
		},
		methods: {
			// 切换选项
			changeTab(index) {
				if (this.tabIndex === index) {
					return;
				}
				this.tabIndex = index;
				// 滚动到指定元素
				this.scrollInto = 'tab' + index;
			},
			// 监听滑动
			onChangeTab(e) {
				uni.showLoading({
					title: '正在加载',
				})
				setTimeout(function() {
					uni.hideLoading()
				}, 500);
				this.changeTab(e.detail.current);
			},
			//选择项目后，带出发货方，收货方
			// selectProjectId(id){
			// 	this.projectList.forEach(item=>{
			// 		if(item.id===id)
			// 		{
			// 			//this.deliveryId=item.shipList
			// 			console.log(item.shipList)
			// 		}
			// 	})
			// },
			//收货方
			selectShipId(e){
				if(!e)
				{
					this.formData.shipContacts=''      //发货方联系人
					this.formData.shipContactTel=''     //发货方联系电话
					this.formData.originDistractId=''		//发货方省市区、县ID
					this.formData.originDistractName=''    //发货方省市区名称
					this.formData.originAddress=''  		//发货方详细地址
				}
			},
			//发货方
			selectDeliveryId(e){
				if(!e)
				{
					this.formData.deliveryContacts=''      //收货方联系人
					this.formData.deliveryContactTel=''     //收货方联系电话
					this.formData.destinationDistractId=''		//收货方省市区、县ID
					this.formData.destinationDistractName=''	//收货方省市区名称
					this.formData.destinationAddress='' 		//收货方详细地址
				}
			},
			//打开发货方地址簿
			open_shipAddress(){
				if(this.formData.parentId!=0)
				{
					uni.showToast({
						icon:'none',
						title:'子订单无法编辑'
					})
				    return
				}
				//获取地址簿
				this.shipId.forEach(item=>{
					if(item.value===this.formData.shipId)
					{
						this.addressList_ship=JSON.parse(item.customer).bookList
					}
				})
				this.$refs.alertDialog_address_ship.open()
			},
			//打开收货方地址簿
			open_deliveryAddress(){
				if(this.formData.parentId!=0)
				{
					uni.showToast({
						icon:'none',
						title:'子订单无法编辑'
					})
				    return
				}
				//获取地址簿
				this.deliveryId.forEach(item=>{
					if(item.value===this.formData.deliveryId)
					{
						this.addressList_delivery=JSON.parse(item.customer).bookList
					}
				})
				this.$refs.alertDialog_address_delivery.open()
			},
			//选择地址->发货方
			radioChange_ship(e) {
				//设置为地址
				this.address_ship=JSON.parse(e.detail.value);
			},
			//选择地址->收货方
			radioChange_delivery(e) {
				//设置为地址
				this.address_delivery=JSON.parse(e.detail.value);
			},
			//确认设置地址->发货方
			dialogConfirm_address_ship() {
				this.formData.shipContacts=this.address_ship.contactName     //发货方联系人
				this.formData.shipContactTel=this.address_ship.phone    //发货方联系电话
				this.formData.originDistractId=this.address_ship.bookDistrict		//发货方省市区、县ID
				this.formData.originDistractName=this.address_ship.bookDistrictName//发货方省市区名称
				this.formData.originAddress=this.address_ship.bookAddress  		//发货方详细地址
			},
			//确认设置地址->收货方
			dialogConfirm_address_delivery() {
				this.formData.deliveryContacts=this.address_delivery.contactName   //收货方联系人
				this.formData.deliveryContactTel=this.address_delivery.phone     //收货方联系电话
				this.formData.destinationDistractId=this.address_delivery.bookDistrict	//收货方省市区、县ID
				this.formData.destinationDistractName=this.address_delivery.bookDistrictName		//收货方省市区名称
				this.formData.destinationAddress=this.address_delivery.bookAddress  		//收货方详细地址
			},
			//删除货物信息某一项
			deleteGoodSourceList(index){
				if(this.formData.parentId!=0)
				{
					uni.showToast({
						icon:'none',
						title:'子订单无法删除货物'
					})
				    return
				}
				let that=this
				uni.showModal({
					title: '提示',
					content: '确定删除此条数据吗？',
					success: function(res) {
						if (res.confirm) {
							that.goodSourceList.splice(index,1)
						}
					}
				});
				
			},
			//新增货物信息
			addGoodSourceList(){
				if(this.formData.parentId!=0)
				{
					uni.showToast({
						icon:'none',
						title:'子订单无法新增货物'
					})
				    return
				}
				getSourceList({pageNum:1,pageSize:1000}).then(res=>{
					this.allGoodsList=res.rows.map(item=>{
						let flag=false
						if(this.goodSourceList.length!==0)
						{
							this.goodSourceList.forEach(item2=>{
								if(item2.originGoodId==item.goodId)
								{
									flag=true
								}
							})
						}
						return {
							value:JSON.stringify(item),
							text:item.goodCode+' '+item.goodsName+' '+this.goodsType[item.goodsType]+' '+item.produceDistrictName,
							disable: flag
						}
					})
				})
				this.$refs.alertDialog.open()
			},
			//确认新增货物
			dialogConfirm() {
				if(this.goods.length)
				{
					this.goods.forEach(item=>{
						let goods=JSON.parse(item)
						this.goodSourceList.push({
							originGoodId:goods.goodId,
							...goods
						})
					})
				}
				
			},
			selectPickupTime(){
				this.formData.pickupTime+=':00';
			},
			selectArrivalTime(){
				this.formData.arrivalTime+=':00';
			},
			//提交订单
			submit() {
				let that = this
				this.$refs.form.validate().then(res => {
					uni.showLoading({
						title: '正在提交...',
					})
					
					//货物信息
					this.formData.goodSourceList=this.goodSourceList
					addOrder(that.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							uni.showToast({
								title: '提交成功',
								icon: 'none'
							})
							let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
							let nowPage = pages[pages.length - 1]; //当前页页面实例
							let prevPage = pages[pages.length - 2]; //上一页页面实例
							prevPage.$vm.otherFun('1') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
							uni.navigateBack({
								delta: 1 // 可以不傳delta值，默認為1
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}
					})
				}).catch(err => {
					uni.showToast({
						title: err[0].errorMessage,
						icon: 'none'
					})
				})
			},
			//修改订单
			submit_update() {
				let that = this
				this.$refs.form.validate().then(res => {
					uni.showLoading({
						title: '正在提交...',
					})
					
					//货物信息
					this.formData.goodSourceList=this.goodSourceList
					that.formData.goodOrderId = that.goodOrderId
					updateOrderProfile(that.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							uni.showToast({
								title: '修改成功',
								icon: 'none'
							})
							let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
							let nowPage = pages[pages.length - 1]; //当前页页面实例
							let prevPage = pages[pages.length - 2]; //上一页页面实例
							prevPage.$vm.otherFun('1') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
							setTimeout(() => {
								uni.navigateBack({
									delta: 1 // 可以不傳delta值，默認為1
								})
							}, 1000)
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}
					})
				}).catch(err => {
					uni.showToast({
						title: err[0].errorMessage,
						icon: 'none'
					})
				})
			},
		},
	}
</script>

<style scoped>
	.pagecontrol-top-scroll {
		height: 40px;
		width: 100%;
		white-space: nowrap;
		box-sizing: border-box;
		border-bottom: 1rpx solid #ededed;
		background-color: #f8f8f8;
	}

	.pagecontrol-top-title {
		height: 100%;
		width: 100%;
		display: flex;
		justify-content: space-around;
	}

	.pagecontrol-top-text {
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		text-align: center;
	}

	.pagecontrol-top-normal {
		color: #656565;
		font-size: 16px;
	}

	.pagecontrol-top-selected {
		color: #000000;
		font-weight: bold;
		font-size: 16px;
	}

	.pagecontrol-bottom-line {
		width: 50vw;
		height: 3px;
		margin-top: 8px;
		background-color: #bf5f09;
		border-radius: 11px;
	}

	.pagecontrol-bottom-line-show {
		visibility: visible;
	}

	.pagecontrol-bottom-line-visibility {
		visibility: hidden;
	}

	.buttonHover {
		opacity: 0.6;
	}
	::v-deep .file-title[data-v-363ace0e] {
	    font-size: 12px;
	    color: #333;
	}
	
	::v-deep .files-button[data-v-4f822398]{
		height: 100px;
		display: flex;
		justify-content: center;
		align-items: center;
		border-width: 1px;
		border-style: solid;
		border-color: rgb(238, 238, 238);
		border-radius: 4px;
	}
	
	.source{
		height: 120px;
		padding: 10px;
		display: flex;
		flex-direction: row;
		align-items: center;
		border-bottom: 1px solid #ededed;
		background-color: #ffffff;
		position: relative;
	}
	::v-deep .uni-select__input-box{
		width: 0vw;
	}
	::v-deep .uni-border-left{
	    border-left-color: #f0f0f0;
	    border-left-style: solid;
	    border-left-width: 1px;
	    background-color: rgb(157,81,38);
	    border-radius: 0 0 11px 0;
	    /* color: white; */
	}
	::v-deep .uni-button-color{
	    color: #ffffff;
	}
</style>